<?php


namespace app\common\cachemodel;


use app\common\model\BaseCache;
use think\Log;
use XznsTools\cache\CacheManage;

class ZlRegisterPackageSendRecode extends BaseCache
{
    protected $table = 'wechat_backup_07_18_14_43_00.zl_register_package_send_recode';
    protected $cacheModel = 'user.register_package_send_recode';

    /**
     * 获取用户是否领赠送过新手礼包
     * @param int $uid
     * @return bool
     * @throws \Exception
     */
    public function getUserHasSendPackage(int $uid): bool
    {
        $data = CacheManage::getInstance()->setCacheConfig($this->cacheModel, $uid)->getDataAndSet(function () use ($uid)
        {
            try
            {
                $data = $this->where('uid', $uid)->count();
            }
            catch (\Exception $e)
            {
                Log::write('获取用户用户是否领赠送过新手礼包异常：' . $e->getMessage(), 'error');
                $data = 0;
            }

            return $data;
        });

        return $data ? true : false;
    }
}
